<?php
session_start();
if ($_SESSION['Status'] != '1') {
    header('Location: signup.php');
}
$id = $_SESSION['name'];
//include 'header.php';
$query = "SELECT t.* , a.* FROM tasks t LEFT JOIN assignment a ON t.Users_email=a.tasks_Users_email WHERE t.users_email = '$id'";
include "dbconnection.php";
if (!$result = mysql_query($query))
    die("Could not execute query<br/>" . mysql_error());
include "dbconnectionclose.php";
?>
    <div class="page-header">
        <div class="page-header-content">
            <h1>Tasks</h1>
        </div>
    </div>
<div class="page secondary">

    <div class="page-region">
        <div class="page-region-content">
            <div class="grid">
                <div class="row">
                    <div class="">
                            <div class="" style="width: 100%">
                                <h2 class="fg-color-blue">Current Tasks<button class="bg-color-blue fg-color-white button place-right" id="addTask">New</button></h2>
                            </div>
                            <script type="text/javascript">
                                $(document).ready(function(){
                                    $('#addTask').click(function(e) {
                                        $.Dialog({
                                            'title'      : 'Add Task',
                                            'draggable':true,
                                            'content'    : '<form id="task"><table style="border-color: white;">'+
                                                '<tr><td><p><label>Task:</label></td><td><input class="with-helper input-control text" name="taskName" type="text" autofocus="" placeholder="ex: 2012/2013"/></p></td></tr>'+
                                                '<tr><td><p><label>Type:</label></td><td><select type="text" autofocus="" name="type" placeholder=""><option value="Reminder">Reminder</option><option value="Assignment">Assignment</option></select></p></td></tr>'+
                                                '<tr><td><p><label>Start date:</label></td><td><input class="with-helper input-control text" type="text" autofocus="" name="s_time" placeholder=""/></p></td></tr>'+
                                                '<tr><td><p><label>Start time:</label></td><td><input class="with-helper input-control text" type="text" autofocus="" name="s_time" placeholder=""/></p></td></tr>'+
                                                '<tr><td><p><label>Start time:</label></td><td><input class="with-helper input-control text" type="text" autofocus="" name="s_time" placeholder=""/></p></td></tr>'+
                                                '<tr><td><p><label>End time:</label></td><td><input class="with-helper input-control text" name="e_time" type="text" autofocus="" placeholder=""/></p></td></tr>'+
                                                '<tr><td><p><label>Description:</label></td><td><input class="with-helper input-control text" name="desc" type="text" autofocus="" placeholder=""/></p></td></tr>'+
                                                '</table></form>',
                                            'buttons'    : {
                                                'Ok'    : {
                                                    'action': function() {
                                                        var data_acyr = $('#task').serialize();
                                                        $.ajax({
                                                            url:'manageTasks.php',
                                                            type:"POST",
                                                            data: data_acyr,
                                                            success:function(data){
                                                                var pagedata = $(data);
                                                                if(pagedata.find("h4").html()=="Successful!"){
                                                                    alert("success");
                                                                    alert(pagedata.html());
                                                                }else{
                                                                    alert(pagedata.html());
                                                                }
                                                            }
                                                        });
                                                    }
                                                },
                                                'Cancel'     : {
                                                    'action': function() {}
                                                }
                                            }
                                        });
                                    });
                                });
                            </script>
                        <div class="tile double quadro-vertical bg-color-teal" style="outline: 0px;">
                            <div class="tile-content" id="taskList">
                                <blockquote class="tertiary-text padding10 bg-color-white fg-color-blueDark" onclick="" style="margin-bottom: 10px;">Task Name</blockquote>
                                <?php
                                for ($counter = 0; $row = mysql_fetch_array($result); $counter++) {
                                    $name = $row['name'];
                                    print("<blockquote class='tertiary-text padding10 bg-color-white fg-color-blueDark' onclick='details()' style='margin-bottom: 10px;'>$name</blockquote>");
                                }
                                ?>
                                <script type="text/javascript">
                                    var dataString = $row[name];
                                    function details(name){
                                        alert(name);
                                        $.ajax({
                                            url:'manageacyr.php',
                                            type:"POST",
                                            data:dataString,
                                            success:function(data){
                                                var pagedata = $(data);
                                                if(pagedata.find("h4").html()=="Successful!"){
                                                    alert("success");
                                                    alert(pagedata.html());
                                                }else{
                                                    alert(pagedata.html());
                                                }
                                            }
                                        });
                                    }    
                                </script>
                            </div>
                        </div>
                        <div class="tile triple quadro-vertical bg-color-lighten place-right" style="outline: 0px;">
                            <div class="tile-content" id="taskDetails">
                                <div>
                                    <div>
                                        <h1>Task Type</h1>
                                        <h2>task Name</h2>
                                        <h3>Subject (if any)</h3>
                                        <div class="divider"></div>
                                        <p>Start day</p>
                                        <p>End Date</p>
                                        <div class="divider"></div>
                                        <div class="slider" data-role="slider">
                                        </div>
                                        <div>
                                            Details
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>